﻿<view:BaseView x:Class="ModernUILogViewer.Content.ContentLogTail"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d" 
             xmlns:mscorlib="clr-namespace:System;assembly=mscorlib"
             xmlns:view="clr-namespace:ModernUILogViewer.View"
             xmlns:helper="clr-namespace:ModernUILogViewer.Elements.Helpers"
             xmlns:avalon="http://icsharpcode.net/sharpdevelop/avalonedit"               
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"                
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"                         
             d:DesignHeight="600" d:DesignWidth="600">

    <DockPanel>
        <StackPanel MinWidth="100" DockPanel.Dock="Top">
            <TextBlock Text="LOG FILE LOCATION" Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopMargin}" />
            <TextBlock Margin="{StaticResource DefaultTopMargin}">
                Enter a local or remote file accessible by http protocol
            </TextBlock>
            <TextBox
                IsReadOnly="False"                
                Margin="{StaticResource DefaultTopMargin}"                 
                Text="{Binding Filename, Mode=TwoWay}">
                <TextBox.Style>                    
                    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
                        <Setter Property="IsEnabled" Value="True" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsProcessing}" Value="True">
                                <Setter Property="IsEnabled" Value="False" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>
            </TextBox>

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}">
                <Button Content="Run" HorizontalAlignment="Center" Width="120" Command="{Binding StartTailCommand}" >
                    <Button.Style>
                        <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
                            <Setter Property="IsEnabled" Value="True" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsProcessing}" Value="True">
                                    <Setter Property="IsEnabled" Value="False" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                </Button>
                <Button Content="Stop" HorizontalAlignment="Center" Width="120" Command="{Binding StopTailCommand}" IsEnabled="{Binding IsProcessing}" Margin="{StaticResource DefaultLeftMargin}" />
            </StackPanel>
            <Grid Margin="{StaticResource DefaultTopMargin}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20*"></ColumnDefinition>
                    <ColumnDefinition Width="40*"></ColumnDefinition>
                    <ColumnDefinition Width="40*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="CONTENT" Style="{StaticResource Heading2}" />
                <TextBlock Grid.Column="1" VerticalAlignment="Center">
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding LastModified}" Value="{x:Static mscorlib:DateTime.MinValue}">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                    <Run FontWeight="Bold" Text="Downloaded: "></Run>
                    <Run Text="{Binding DownloadedContentLength}"></Run>
                </TextBlock>
                <TextBlock Grid.Column="2" VerticalAlignment="Center">
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding LastModified}" Value="{x:Static mscorlib:DateTime.MinValue}">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                    <Run FontWeight="Bold" Text="Last Modified: "></Run>
                    <Run Text="{Binding LastModified, StringFormat='dd/MM/yyyy HH:mm:ss'}"></Run>
                </TextBlock>
            </Grid>
        </StackPanel>

        <Border BorderThickness="1" BorderBrush="{DynamicResource ButtonBorder}">
            <avalon:TextEditor
                ShowLineNumbers="True"
                DockPanel.Dock="Bottom"
                Margin="0, 8, 0, 4"            
                HorizontalScrollBarVisibility="Auto" 
                VerticalScrollBarVisibility="Auto"        
                x:Name="contentText"
                >
                <avalon:TextEditor.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Clear text" Command="{Binding ClearContentCommand}">
                            <MenuItem.Icon>
                                <Path Fill="#FF2B2B2B"
                              Width="14.3775"
                              Height="14"
                              Canvas.Left="0.311264"
                              Canvas.Top="0.500005"
                              Stretch="Fill"
                              Data="F1 M 43,30L 50.75,30L 43,22.25L 43,30 Z M 52,34L 39,34L 39,21L 24,21L 24,39L 20,43L 20,17L 43.25,17L 56,29.75L 56,59L 36.5,59L 40.5,55L 52,55L 52,34 Z M 35.1379,40.67L 38.4967,44.0287L 32.8988,49.6266L 38.4967,55.2246L 35.1379,58.5833L 29.54,52.9854L 23.9421,58.5833L 20.5833,55.2246L 26.1813,49.6266L 20.5833,44.0287L 23.9421,40.67L 29.54,46.2679L 35.1379,40.67 Z " />
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </avalon:TextEditor.ContextMenu>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="ClearTextRequestedEvent" SourceObject="{Binding}">
                        <ei:ChangePropertyAction PropertyName="Text" Value="{x:Null}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <i:Interaction.Behaviors>
                    <!--<helper:AvalonEditBehaviour SetText="{Binding Text, Mode=OneWay}"/>-->
                    <helper:AppendTextBehavior AppendTextAction="{Binding AppendTextAction, Mode=OneWayToSource}" AutoScrollLastLine="{Binding AutoScrollLastLine}" />
                </i:Interaction.Behaviors>
            </avalon:TextEditor>
        </Border>
    </DockPanel>
</view:BaseView>
